package com.frostmourne.mxsguimaker.objects;

import com.frostmourne.mxsguimaker.MXSGuiMaker;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;

import java.util.HashMap;
import java.util.Map;

public class ScriptExpand {

    public static final Map<String,String> SCRIPTS = new HashMap<>();

    public static String staticGetExpandScript(String name){
        return SCRIPTS.getOrDefault(name, null);
    }

    public static Object staticExecute(String script, Object... objects){


        return new JSEngine().invoke(script,"main",objects);
    }

//    public StaticClass importClass(String name){
//
//        Class<?> c = null;
//
//        try {
//            c = Class.forName(name);
//        } catch (ClassNotFoundException e) {
//            try {
//                c = Class.forName(name,false, MXSGuiMaker.INSTANCE.getLoader());
//            } catch (ClassNotFoundException ignored) {
//            }
//        }
//
//        if (c != null){
//
//            return jdk.dynalink.beans.StaticClass.forClass(c);
//
//        }
//
//        return null;
//
//
//    }

    public Class<?> javaClass(String name,ClassLoader loader){
        try {
            return Class.forName(name,false,loader);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }


    public Object execute(String script,Object... objects){
        return staticExecute(script,objects);
    }

    public String getExpandScript(String name){
        return staticGetExpandScript(name);
    }

    public String loadPapi(Player player,String placeholder){
        return PlaceholderAPI.setPlaceholders(player,placeholder);
    }

}
